package com.acme.bankapp.domain.bank;

import java.util.ArrayList;
import java.util.List;

public class QueueImpl implements Queue {

	private List<Email> mails = new ArrayList<Email>();
	
	public synchronized void addEmail(Email email) {
		this.mails.add(email);
		notify();
	}

	public synchronized Email getEmail() {
		while(mails.isEmpty()) {
			try {
				wait();
			} catch (InterruptedException e) {}
		}
		return this.mails.remove(0);
	}
	
	public boolean isEmpty() {
		return this.mails.isEmpty();
	}
	
}